package edu.mis.modules.orderList;

import com.jfinal.core.Controller;

import edu.mis.model.OrderList;
import edu.mis.model.Type;



public class OrderListController extends Controller {
	
	static OrderListService service = new OrderListService();
	
	public void index() {
		render("orderList.html");
	}

	
	public void list(){
		setAttr("data", service.findAllOrderListWithSeat());
		renderJson();  
	}

	/**
	 * 添加商品视图
	 */
	public void add() {
		render("add.html");  //（默认对应add.html，否则需显性指定，如render("addOrderList.html")）
	}

	public void addOrderList(){
		OrderList orderList  =  getModel(OrderList.class);   //使用getModel方法获取表单值，表单中name应使用对象名.属性名，如orderList.id, orderList.orderListQty,详见jfinal手册
		service.addOrderList(orderList);
		renderJson(); 
	}
	
	/**
	 * 修改商品信息视图（默认对应edit.html，否则需显性指定，如render("editOrderListQty.html")，）
	 */
	public void edit() {
		setAttr("orderList", service.findOrderListById(getParaToInt("id")));
	}

    public void updateOrderList(){
        OrderList orderList  =  getModel(OrderList.class);
        if(service.updateOrderList(orderList)){
            setAttr("result", true);
            setAttr("msg", "修改商品信息成功!");
        }else{
            setAttr("result", false);
        }
        renderJson();
    }


	
	/**
	 * 商品分类视图
	 */
	public void view_classify() {
		render("classify.html");
		setAttr("orderList", service.findOrderListById(getParaToInt("id")));  //此处orderList应与表单中${(orderList.name)!}等中的orderList保持一致。
		setAttr("type",Type.dao.findAll());//分类前得到所有权限
	}
	
	/**
	 * 商品分类
	 */
	public void classify(){
		int id=this.getParaToInt("id");   
		int typeId = this.getParaToInt("typeId");
		if(service.classifyOrderList(id, typeId)){
			setAttr("result", true);
			setAttr("msg", "商品分类成功!");
		}else{
			setAttr("result", false);
			setAttr("msg", "商品分类失败!");
		}
		renderJson();
	}
	/**
	 * 删除商品
	 * 测试访问地址：localhost:8080/orderList/delete?id=1
	 */
	public void delete() {
		if(service.deleteOrderListById(getParaToInt("id"))){
			setAttr("result", true);
			setAttr("msg", "删除商品成功!");
		}else{
			setAttr("result", false);
		}	
		renderJson();
	}
	public void detail(){
		setAttr("orderList", service.findOrderListById((int)getParaToInt("id")));
		render("detail.html");

	}
	public void detail1(){
		setAttr("data", service.findAllOrderDetailsById((int)getParaToInt("id")));
		renderJson();
	}
	/**
	 * 订单结账
	 */
	public void checkout(){
		int id=this.getParaToInt("id");
		int seatId=this.getParaToInt("seatId");
		if(service.checkOutOrderList(id,seatId, 2)){
			setAttr("result", true);
			setAttr("msg", "订单结账成功!");
		}else{
			setAttr("result", false);
			setAttr("msg", "订单结账失败!");
		}
		renderJson();
	}
	public void view_checkoutList(){
		render("checkoutList.html");
	}
	public void checkoutList(){
		setAttr("data",service.findAllUnpaidRecord());
		renderJson();
	}
	
	

}